/**
 * 断言类
 */
package com.cnfangmao.asserts;


import java.util.Collection;

import org.apache.commons.lang.StringUtils;

import com.cnfangmao.exception.PropertyException;
import com.cnfangmao.exception.message.ExceptionMessagePkg;


public class Asserter {
	/****
	 * 判断一个字符串是否全为数字
	 * @param text
	 * @param message
	 */
	public static void isAssignable(Class<?> superType, Class<?> subType) {
		isNull(superType,superType.getSimpleName());
		isNull(subType,superType.getSimpleName());

		if(!superType.isAssignableFrom(subType))
		{
			throw new PropertyException("exception.isAssignable",ExceptionMessagePkg.class.getPackage().getName(),superType.getSimpleName(),subType.getSimpleName());
		}
	}
	
	/***
	 * 判断一个对象是否为NULL
	 * @param object
	 */
	public static void isNull(Object object)
	{
		if(object==null)
		{
			throw new PropertyException("exception.isNull1",ExceptionMessagePkg.class.getPackage().getName());
		}
	}

	/***
	 * 判断一个对象是否为NULL
	 * @param object
	 */
	public static void isNull(Object object,String strMsg)
	{
		isNull(object,ExceptionMessagePkg.class.getPackage().getName(),"exception.isNull2",strMsg);
	}
	
	public static void isEmpty(Collection col,String strMsg)
	{
		if(col==null || col.isEmpty())
		{
			throw new PropertyException("exception.isNull2",ExceptionMessagePkg.class.getPackage().getName(),strMsg);
		}
	}
	
	/***
	 * 判断一个对象是否为NULL
	 * @param object
	 */
	public static void isNull(Object object,String moduleName,String strMsgID,Object ...args)
	{
		if(object==null)
		{
			throw new PropertyException(strMsgID,moduleName,args);
		}
		
		if(object instanceof String)
		{
			String value=(String)object;
			if(StringUtils.isEmpty(value))
			{
				throw new PropertyException(strMsgID,moduleName,args);
			}
		}
	}

	/***
	 * 判断一个对象是否为NULL
	 * @param object
	 */
	public static void isNotNull(Object object)
	{
		if(object!=null)
		{
			throw new PropertyException("exception.isNull1",ExceptionMessagePkg.class.getPackage().getName());
		}
	}

	/***
	 * 判断一个对象是否为NULL
	 * @param object
	 */
	public static void isNotNull(Object object,String strMsg)
	{
		isNotNull(object,ExceptionMessagePkg.class.getPackage().getName(),"exception.isNull2",strMsg);
	}
	
	/***
	 * 判断一个对象是否为NULL
	 * @param object
	 */
	public static void isNotNull(Object object,String moduleName,String strMsgID,Object ...args)
	{
		if(object!=null)
		{
			throw new PropertyException(strMsgID,moduleName,args);
		}
	}

	/****
	 * 判断一个字符串是否为null或为空
	 * @param strText
	 * @param strMsg
	 * @param strMsgID
	 */
	public static void hasLength(String strText,String strMsg,String moduleName,String strMsgID)
	{
		if(StringUtils.isEmpty(strText))
		{
			throw new PropertyException(strMsgID,moduleName,strMsg);
		}
	}
	
	/****
	 * 判断一个字符串是否为null或为空
	 * @param strText
	 * @param strMsg
	 * @param strMsgID
	 */
	public static void hasLength(String strText,String strMsg)
	{
		if(StringUtils.isEmpty(strText))
		{
			throw new PropertyException("exception.haslength2",ExceptionMessagePkg.class.getPackage().getName(),strMsg);
		}
	}
	/****
	 * 判断一个字符串是否为null或为空
	 * @param strText
	 * @param strMsg
	 * @param strMsgID
	 */
	public static void hasLength(String strText)
	{
		if(StringUtils.isEmpty(strText))
		{
			throw new PropertyException("exception.haslength1",ExceptionMessagePkg.class.getPackage().getName());
		}
	}
	
	/***
	 * 判断两个浮点数是否相等 
	 * @param src
	 * @param dest
	 */
	public static void equal(float src,float dest,String moduleName,String strMsgID,String strMsg)
	{
		if(src==dest)
		{
			throw new PropertyException(strMsgID,moduleName,strMsg,dest);
		}
	}

	/***
	 * 判断两个浮点数是否相等 
	 * @param src
	 * @param dest
	 */
	public static void equal(float src,float dest,String moduleName,String strMsg)
	{
		if(src==dest)
		{
			throw new PropertyException("exception.numberequal",moduleName,strMsg,dest);
		}
	}

	/***
	 * 判断两个浮点数是否相等 
	 * @param src
	 * @param dest
	 */
	public static void less(float src,float dest,String moduleName,String strMsgID,String strMsg)
	{
		if(src<dest)
		{
			throw new PropertyException(strMsgID,moduleName,strMsg,dest);
		}
	}

	/***
	 * 判断两个浮点数是否相等 
	 * @param src
	 * @param dest
	 */
	public static void less(float src,float dest,String moduleName,String strMsg)
	{
		if(src<dest)
		{
			throw new PropertyException("exception.numberless",moduleName,strMsg,dest);
		}
	}	

	/***
	 * 判断两个浮点数是否相等 
	 * @param src
	 * @param dest
	 */
	public static void greater(float src,float dest,String moduleName,String strMsgID,String strMsg)
	{
		if(src>dest)
		{
			throw new PropertyException(strMsgID,moduleName,strMsg,dest);
		}
	}

	/***
	 * 判断两个浮点数是否相等 
	 * @param src
	 * @param dest
	 */
	public static void greater(float src,float dest,String moduleName,String strMsg)
	{
		if(src>dest)
		{
			throw new PropertyException("exception.numbergreater",moduleName,strMsg,dest);
		}
	}
}
